
from lib.api import *
import re
from lib.urls import *


def suite_setup():
    INFO('返回token')
    global auth_token
    auth_token = am.getToken()




class API_3016:
    name = 'API_3016'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：PA控制接口 测试     #3.4')
        INFO("前置条件：token正确，'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb04_1'正确")
        urlpara = {
            'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb04_1'
        }
        response = requests.post(url_Target_Address+url_Control_PAControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[20][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





class API_3017:
    name = 'API_3017'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：PA控制接口 测试     #3.4')
        INFO("前置条件：token过期，'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb04_1'正确")
        urlpara = {
            'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb04_1'
        }
        response = requests.post(url_Target_Address+url_Control_PAControl,
                                 headers={
                                     "auth-token": 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMTkzNzIwNCwidXNlcklkIjoieXp5YWRtaW4ifQ.xVITR8Cn0zLrJSA3tKMt48bTyk6tFhlRwjIp4e_yFys'
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[21][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))



class API_3018:
    name = 'API_3018'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：PA控制接口 测试     #3.4')
        INFO("前置条件：token 不填，'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb04_1'正确")
        urlpara = {
            'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb04_1'
        }
        response = requests.post(url_Target_Address+url_Control_PAControl,
                                 # headers={
                                 #     "auth-token": 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMTkzNzIwNCwidXNlcklkIjoieXp5YWRtaW4ifQ.xVITR8Cn0zLrJSA3tKMt48bTyk6tFhlRwjIp4e_yFys'
                                 # },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[21][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))



class API_3019:
    name = 'API_3019'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：PA控制接口 测试     #3.4')
        INFO("前置条件：token正确，'pointName':'ZGZ.PSD.CONTROL.ddocb_0'错误，PSD的控点存在，但不在目标控点内")
        urlpara = {
            'pointName':'ZGZ.PSD.CONTROL.ddocb_0'
        }
        response = requests.post(url_Target_Address+url_Control_PAControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[21][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))


class API_3020:
    name = 'API_3020'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：PA控制接口 测试     #3.4')
        INFO('前置条件：token 正确， pointName 为空')
        # urlpara = {
        #     'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb04_1'
        # }
        response = requests.post(url_Target_Address+url_Control_PAControl,
                                 headers={
                                     "auth-token": auth_token
                                 }
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[21][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))




